package cn.pzh.amqp.listener;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class MqListener {
    @RabbitListener(queues = "xzh")
    public void listenXzhQueue(String mess){
        System.out.println("mq消费消息："+mess);
    }
    @RabbitListener(queues = "fanout.queue1")
    public void listenFanoutQueue1(String mess){
        System.out.println("fanout1:"+mess);
    }
    @RabbitListener(queues = "fanout.queue2")
    public void listenFanoutQueue2(String mess){
        System.out.println("fanout2:"+mess);
    }
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("direct.queue1"), //队列
            exchange = @Exchange(value = "direct",type = ExchangeTypes.DIRECT), //交换机
            key = {"red","blue"}  //key
    ))
    public void listenDirectQueue1(String mess){
        System.out.println("direct.queue1"+mess);
    }
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("direct.queue2"),
            exchange = @Exchange(value = "direct",type = ExchangeTypes.DIRECT),
            key = {"red","yellow"}
    ))
    public void listenDirectQueue2(String mess){
        System.out.println("direct.queue2"+mess);
    }
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("topic.queue1"), //队列
            exchange = @Exchange(value = "topic",type = ExchangeTypes.TOPIC), //交换机
            key = "china.#"  //key #表示通配符
    ))
    public void listenTopicQueue1(String mess){
        System.out.println("topic.queue1"+mess);
    }
}
